// UrlRewriter - A .NET URL Rewriter module
// Version 1.7
//
// Copyright 2006 Intelligencia
// Copyright 2006 Seth Yates
// 

using System;
using System.Net;
using System.Web;

namespace Intelligencia.UrlRewriter.Actions
{
	/// <summary>
	/// Sets the StatusCode.
	/// </summary>
	public class SetStatusAction : IRewriteAction
	{
		/// <summary>
		/// Default constructor.
		/// </summary>
		/// <param name="statusCode">The status code to set.</param>
		public SetStatusAction(HttpStatusCode statusCode)
		{
			_statusCode = statusCode;
		}

		/// <summary>
		/// The status code.
		/// </summary>
		public HttpStatusCode StatusCode
		{
			get
			{
				return _statusCode;
			}
			set
			{
				_statusCode = value;
			}
		}

		/// <summary>
		/// Executes the action.
		/// </summary>
		/// <param name="context">The rewriting context.</param>
		public virtual void Execute(RewriteContext context)
		{
			context.StatusCode = StatusCode;
		}

		/// <summary>
		/// The Processing directive.
		/// </summary>
		public RewriteProcessing Processing
		{
			get
			{
				if ((int)StatusCode >= 300)
				{
					return RewriteProcessing.StopProcessing;
				}
				else
				{
					return RewriteProcessing.ContinueProcessing;
				}
			}
		}

		private HttpStatusCode _statusCode;
	}
}
